home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Video
/
World of Video.iso
/
gfxprograms
/
boards
/
retina
/
rblanke2.lha
/
RBlankers
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-12
|
9KB
|
412 lines
#include <exec/memory.h>
#include <exec/ports.h>
#include <exec/execbase.h>
#include <graphics/displayinfo.h>
#include <intuition/intuitionbase.h>
#include <intuition/gadgetclass.h>
#include <libraries/commodities.h>
#include <libraries/gadtools.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <utility/tagitem.h>
#include <clib/alib_protos.h>
#include <clib/commodities_protos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/macros.h>
#include <clib/retina_protos.h>
#include <libraries/retina.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <pragmas/commodities_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/retina_pragmas.h>
#include "blanker.h"
extern UBYTE *VersionString;
void
chkabort(void)
{
}
/*
* Common Definitions
*/
struct IntuitionBase *IntuitionBase;
struct RetinaBase *RetinaBase;
struct Library *CxBase, *GadToolsBase, *IconBase;
#define FINDPROCPORT (&((struct Process *)SysBase->ThisTask)->pr_MsgPort)
extern struct EasyStruct quitreq;
/*
* Reports an error using a requestor.
*/
void
Error(char *s)
{
if (s) EasyRequest(NULL,&quitreq,NULL,s);
}
/*
* Definitions for our Commodity
*/
extern struct NewBroker NewBroker;
struct MsgPort *CxPort;
UBYTE *PopKey;
UBYTE *BlankKey;
LONG TimeOut, ClientTimeOut;
/*
* Definitions for Server/Client Communication
*/
BYTE bsp_TimerSig, bsp_InputSig, bsp_ClientSig;
struct Task *ServerProcess;
/*
* The following functions are used to track resources.
*/
struct ToolNode {
struct ToolNode *Next;
void *Tool;
void (*RemProc) (void *, LONG);
LONG Size;
}
*ToolList;
void __regargs
RemTool(void *Tool)
{
struct ToolNode *Ptr, *OPtr;
Ptr = ToolList;
OPtr = NULL;
while (Ptr) {
if (Ptr->Tool==Tool) {
Ptr->RemProc(Ptr->Tool,Ptr->Size);
if (OPtr)
OPtr->Next=Ptr->Next;
else
ToolList=Ptr->Next;
FreeMem(Ptr,sizeof(struct ToolNode));
return;
} else {
OPtr=Ptr;
Ptr=Ptr->Next;
}
}
}
void __regargs
Quit(int ReturnCode, char *s)
{
while (ToolList)
RemTool(ToolList->Tool);
if (ReturnCode) Error(s);
exit(ReturnCode);
}
void __regargs
AddTool(void *NewTool, void (*ProcPtr)(void *, LONG), LONG NewSize, char *errmsg)
{
struct ToolNode *Ptr;
void (*NewRemProc) (void *, LONG);
NewRemProc = ProcPtr;
if (NewTool == NULL)
Quit(10,errmsg);
if ((Ptr = AllocMem(sizeof(struct ToolNode), MEMF_CLEAR)) == NULL) {
NewRemProc(NewTool, NewSize);
Quit(20,"Out of Memory.");
}
Ptr->Next = ToolList;
Ptr->Tool = NewTool;
Ptr->RemProc = NewRemProc;
Ptr->Size = NewSize;
ToolList = Ptr;
}
/*
* Some utility functions
*/
void __stdargs
DeleteMsgPortSafely(struct MsgPort *AnyPort)
{
struct Message *AnyMsg;
while (AnyMsg = GetMsg(AnyPort))
ReplyMsg(AnyMsg);
DeleteMsgPort(AnyPort);
}
int __regargs
ArgIntRange(char **ToolTypes, char *ID, int Min, int Default, int Max)
{
int Val;
Val = ArgInt(ToolTypes, ID, Default);
if ((Val < Min) || (Val > Max))
return Default;
else
return Val;
}
/*
* Our "InputHandler". It signals the server process
* when an input event is received.
*/
void __interrupt __saveds
BlankerAction(CxMsg * CxMsg, CxObj * CO)
{
struct InputEvent *IE;
IE = (struct InputEvent *)CxMsgData(CxMsg);
if (IE->ie_Class == IECLASS_TIMER)
Signal(ServerProcess, 1L << bsp_TimerSig);
else
Signal(ServerProcess, 1L << bsp_InputSig);
}
/*
* Returns the value of a gadget in *Data, if the value is between min and max.
* Otherwise, it sets the gadget to *Data.
*/
LONG
GetNum(struct Window *BlankerWindow, struct Gadget *Gadget, LONG Min, LONG * Data, LONG Max)
{
LONG NewData;
NewData = ((struct StringInfo *)Gadget->SpecialInfo)->LongInt;
if ((NewData < Min) || (NewData > Max)) {
GT_SetGadgetAttrs(Gadget, BlankerWindow, NULL, GTIN_Number, (ULONG) * Data,
TAG_DONE);
return FALSE;
} else {
*Data = NewData;
return TRUE;
}
}
/*
* Function to handle the Commodity Stuff
*/
void __regargs
HandleCxMsg(CxObj * Broker, CxMsg * CxMsg, LONG * TimeUntilBlank,
LONG * ThisTimeOut)
{
ULONG MsgType, MsgID;
MsgType = CxMsgType(CxMsg);
MsgID = CxMsgID(CxMsg);
ReplyMsg((struct Message *)CxMsg);
switch (MsgType) {
case CXM_IEVENT: /* a hotkey was pressed */
switch (MsgID) {
case HOTKEY_OPEN_WINDOW:
OpenBlankerWindow();
break;
case HOTKEY_BLANK_SCREEN:
if (*TimeUntilBlank)
*TimeUntilBlank = *ThisTimeOut = 2L;
}
case CXM_COMMAND:
switch (MsgID) {
case CXCMD_DISABLE: /* Message from Exchange
* (except CXCMD_UNIQUE) */
(void)ActivateCxObj(Broker, FALSE);
break;
case CXCMD_ENABLE:
(void)ActivateCxObj(Broker, TRUE);
break;
case CXCMD_UNIQUE:
case CXCMD_APPEAR:
OpenBlankerWindow();
break;
case CXCMD_DISAPPEAR:
CloseBlankerWindow();
break;
case CXCMD_KILL:
Quit(0,"Normal Termination.");
}
}
}
/*
* This, annoyingly enough, is neccessary because Retina_CloseScreen is
* actually a #pragma and not a real function call. This means you
* can't pass a pointer to Retina_CloseScreen as a function argument
* to AddTool. By adding this wrapper function, we make AddTool work.
*/
void
DestroyScreen(struct RetinaScreen *rs)
{
Retina_CloseScreen(rs);
}
/*
* Create Screen will first attempt to open a "normal" resolution screen.
* If that fails, it will try opening a lower resolution screen.
* If that fails it will return NULL.
*/
struct RetinaScreen *
CreateScreen(UBYTE *colors)
{
struct RetinaScreen *Screen;
if (!(Screen = Retina_OpenScreen(NORMAL_WIDE, NORMAL_HIGH, MID_DEFAULT_08, NULL,NULL)))
if (!(Screen = Retina_OpenScreen(SMALL_WIDE, SMALL_HIGH, MID_DEFAULT_08,NULL, NULL)))
return NULL;
Retina_LoadPalette(Screen, 0, 256, colors);
SpritesOff(Screen);
return Screen;
}
/*
* Functions for Creating/Deleting the Client Process
*/
void __stdargs
DeleteBlankerClient(struct MsgPort * ClientPort)
{
struct ClientMessage ClientMessage;
Forbid();
ClientMessage.bcm_Message.mn_ReplyPort = FINDPROCPORT;
PutMsg(ClientPort, (struct Message *)&ClientMessage);
(void)SetTaskPri(ClientPort->mp_SigTask, SERVER_PRI);
Permit();
(void)WaitPort(ClientMessage.bcm_Message.mn_ReplyPort);
(void)GetMsg(ClientMessage.bcm_Message.mn_ReplyPort);
}
struct MsgPort *__regargs
CreateBlankerClient(void *ClientRoutine, struct ClientMessage *ClientMessage)
{
struct Process *ClientProcess;
struct TagItem ProcTags[3];
ProcTags[0].ti_Tag = NP_Entry;
ProcTags[0].ti_Data = (ULONG) ClientRoutine;
ProcTags[1].ti_Tag = NP_Name;
ProcTags[1].ti_Data = (ULONG) "BlankerClient";
ProcTags[2].ti_Tag = TAG_DONE;
if (ClientProcess = CreateNewProc(ProcTags)) {
ClientMessage->bcm_Message.mn_ReplyPort = FINDPROCPORT;
PutMsg(&ClientProcess->pr_MsgPort, (struct Message *)ClientMessage);
(void)WaitPort(ClientMessage->bcm_Message.mn_ReplyPort);
(void)GetMsg(ClientMessage->bcm_Message.mn_ReplyPort);
(void)SetTaskPri((struct Task *)ClientProcess, CLIENT_PRI);
if (ClientMessage->bcm_Status)
return &ClientProcess->pr_MsgPort;
}
return NULL;
}
/*
* A high-speed psuedo random number generator.
*/
WORD __regargs
Random(WORD Max)
{
static ULONG Num = 0L;
ULONG Sec, Mic;
CurrentTime((ULONG *) & Sec, (ULONG *) & Mic);
Num *= Sec;
Num += Mic;
while (Num > 32767L)
Num = Num >> 1;
return (WORD)(Num % Max);
}
/*
* This is the Client Process's Main Loop
*/
void __interrupt __saveds
RLinesClientProcess(void)
{
struct ClientMessage *ClientMessage;
struct MsgPort *ClientPort;
struct Task *ServerTask;
ULONG ServerSigMask;
struct RetinaScreen *LinesScreen;
LONG NumLines, Speed;
void *plist;
/* wait for Server's initial Message */
ClientPort = FINDPROCPORT;
(void)WaitPort(ClientPort);
ClientMessage = (struct ClientMessage *)GetMsg(ClientPort);
ServerTask = ClientMessage->bcm_Message.mn_ReplyPort->mp_SigTask;
ServerSigMask = ClientMessage->bcm_SigMask;
NumLines = ClientMessage->bcm_Lines;
Speed = ClientMessage->bcm_Speed;
LinesScreen = ClientMessage->bcm_Screen;
if (LinesScreen) {
if ((plist = CreateLines(LinesScreen, NumLines, Speed))== NULL) {
ClientMessage->bcm_Status = FALSE;
Forbid();
ReplyMsg((struct Message *)ClientMessage);
return;
}
}
ClientMessage->bcm_Status = TRUE;
ReplyMsg((struct Message *)ClientMessage);
while ((ClientMessage =
(struct ClientMessage *)GetMsg(ClientPort)) == NULL) {
if (LinesScreen) {
DrawLines(plist, LinesScreen);
}
Signal(ServerTask, ServerSigMask);
}
/* We are requested to finish, so we do. */
Forbid();
ReplyMsg((struct Message *)ClientMessage);
}